// 在这个函数设置和读取turn服务器配置
use crate::db::{db_select::db_select, db_insert::db_insert};
pub struct TurnServerConfig {
    pub server: String,
    pub username: String,
    pub password: String,
}

impl TurnServerConfig {
    pub async fn get() -> Option<TurnServerConfig> {
        if let Ok(server) = db_select("turn_server").await {
            if let Ok(username) = db_select("turn_username").await {
                if let Ok(password) = db_select("turn_password").await {
                    return Some(TurnServerConfig {
                                            server : server.value,
                                            username: username.value,
                                            password: password.value,
                                        });
                }
            }
        }
        return None;    
    }
    
    pub async fn set(server: &str, username: &str, password: &str) {
        db_insert("turn_server", server).await.unwrap();
        db_insert("turn_username", username).await.unwrap();
        db_insert("turn_password", password).await.unwrap();
    }
}